package jrobutt;

public class GameMath
{
    public static float Pi = (float)Math.PI;
    public static float TwoPi = (float)(Math.PI * 2.0f);
    public static float PiOverTwo = (float)(Math.PI / 2.0f);
    
    public static float sqr (float n)
    {
        return n*n;
    }
    
    public static float point_distance (float x1, float y1, float x2, float y2)
    {
        return (float)Math.sqrt(point_distance_sqr(x1, y1, x2, y2));
    }
    public static float point_distance_sqr (float x1, float y1, float x2, float y2)
    {
        return (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
    }
    
    public static float point_direction (float x1, float y1, float x2, float y2)
    {
        return (float)Math.atan2(y2 - y1, x2 - x1);
    }
    
    public static float clamp (float value, float min, float max)
    {
        return Math.min(Math.max(min, value), max);
    }
    
    public static float interpolate_linear (float ratio, float low, float hi)
    {
        return low + (hi - low) * ratio;
    }
    
    public static float interpolate_cubic (float ratio)
    {
        return 3*ratio*ratio - 2*ratio*ratio*ratio;
    }
    
    public static float interpolate_cubic (float ratio, float low, float hi)
    {
        return interpolate_linear(interpolate_cubic(ratio), low, hi);
    }
}
